define(['marked', 'text!pages/article/'],function(marked,text){
    return {
        template : text,
        data : function() {
			return {
				text: '数据加载中...',
				title:'',
				url:location.href
			}
		},
		created : function(){
			this.title=this.$route.params.id

			document.title=this.title+'详情'

			this.$http.get('md/'+this.title).then(function(response){
				this.text=response.data
			}, function(response) {
				this.text='数据加载失败'
			})
		},
		filters : {
			marked: marked
		},
		ready : function(){
			var article=document.querySelector('article')
			var loadComment=function(){
				if(article.scrollTop + document.documentElement.clientHeight >= article.scrollHeight){
					if(typeof(DUOSHUO)==='undefined'){
						window.duoshuoQuery = {short_name:"jwei"}
						var script=document.createElement('script')
						script.src='//static.duoshuo.com/embed.js'
						document.head.appendChild(script)
					}else{
						DUOSHUO.EmbedThread(document.querySelector('.ds-thread'))
					}
				}
			}
			article.addEventListener('scroll',function(){
				loadComment()
			},false)
		}
    }
});
